import axios from 'axios'

export function request(config) {
	// http://152.136.185.210:7878/api/m5/recommend
	const instance = axios.create({
		baseURL: 'http://152.136.185.210:7878/api/m5',
		timeout: 5000
	})
	
	instance.interceptors.request.use(config =>{
		
		// console.log('请求成功被拦截')
		
		return config
		
	},err => {
		// console.log('请求失败被拦截')
		return err
		
	})
	
	instance.interceptors.response.use(res => {
		
		// console.log('响应成功被拦截')
		return res.data
		
	}), err => {
		
		// 响应失败判断
		if(err && err.response){
			switch (err.response.status) {
				case 400:
					err.message = '请求错误'
					break
				case 401:
					err.message = '未授权的访问'
					break
			}
		}
		
		// console.log('响应失败被拦截')
		return err
	}
	
	return instance(config)
	
}
